package com.itholmes.config;

import org.apache.zookeeper.ZooKeeper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

@Configuration
public class Zkconfig {

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Bean
    public Watcher01 myZkWatcher() {
        //创建一个watcher
        return new Watcher01();
    }

    @Bean
    public ZooKeeper create(Watcher01 myZkWatcher) throws IOException {
        System.out.println("准备...");
        ZooKeeper zk = new ZooKeeper("150.158.199.52:2181", 3000,myZkWatcher );
        myZkWatcher.zk = zk;
        System.out.println("连接..");
        return zk;
    }

}
